<!-- 我的 -->
<template>
    <view class="">

        
        <view style="padding: 25rpx;">
            <view class="ni">
                <view class="ni_cell" style="min-height: 150rpx; padding-top: 50rpx; position: relative;">
                    <image @tap="$jump('mine.profile')" src="../../static/aa/set.png" style="position: absolute;right: 20rpx;top: 15rpx;width: 40rpx;height: 40rpx;"></image>
                    <view style="display: flex;align-items: center;">
                        <image @tap="$jump('mine.profile')" :src="image_cache(user.avatar)" style="width: 110rpx;height: 110rpx;border-radius: 10rpx;"></image>
                        <view style="margin-left: 20rpx; position: relative;">
                            <view style="font-size: 35rpx;">{{user.nickname}}</view>
                            <view style="color: #999;font-size: 26rpx;margin-top: 10rpx;">账号:{{user.name}}</view>
                            <view v-if="user.sex ==1 || user.sex == 2">
                                <image style="top: 12rpx; height: 30rpx; right: 0; width: 30rpx; position: absolute;" :src="`/static/img/gender1.png`"   />
                            </view>
                        </view>
                    </view>
                    <view style="display: flex;align-items: center;" @tap="$jump('mine.qrcode')">
                        <image src="../../static/erweima.png" style="width: 60rpx;height: 60rpx;"></image>
                        <uni-icons type='arrowright' color="#333"></uni-icons>
                    </view>
                </view>
            </view>
            <view class="ni">
                <view class="ni_cell" @tap="$jump('mine.bag')">
                    <view style="display: flex; align-items: center;">
                        <image style="margin-right: 25rpx; width: 40rpx;height: 40rpx;" src="../../static/aa/qian.png"></image>
                        <label>我的钱包</label>
                    </view>
                    <uni-icons type="arrowright" color="#666"></uni-icons>
                </view>
            </view>
            <view class="ni">
                <view class="ni_cell" @tap="$jump('friend.shoucang.shoucang')">
                    <view style="display: flex; align-items: center;">
                        <image style="margin-right: 25rpx; width: 40rpx;height: 40rpx;" src="../../static/aa/cang.png"></image>
                        <label>我的收藏</label>
                    </view>
                    <uni-icons type="arrowright" color="#666"></uni-icons>
                </view>
            </view>
            <view class="ni">
                <view class="ni_cell" @tap="$jump('circle.circle',{id:user.id})">
                    <view style="display: flex; align-items: center;">
                        <image style="margin-right: 25rpx; width: 40rpx;height: 40rpx;" src="../../static/aa/dong.png"></image>
                        <label>我的动态</label>
                    </view>
                    <uni-icons type="arrowright" color="#666"></uni-icons>
                </view>
            </view>
            <view class="ni">
                <view class="ni_cell" @tap="$jump('mine.menu?act=setting')">
                    <view style="display: flex; align-items: center;">
                        <image style="margin-right: 25rpx; width: 40rpx;height: 40rpx;" src="../../static/aa/an.png"></image>
                        <label>安全设置</label>
                    </view>
                    <uni-icons type="arrowright" color="#666"></uni-icons>
                </view>
            </view>
            <view class="ni">
                <view class="ni_cell" @tap="$jump('mine.note')">
                    <view style="display: flex; align-items: center;">
                        <image style="margin-right: 25rpx; width: 40rpx;height: 40rpx;" src="../../static/aa/tong.png"></image>
                        <label>通知设置</label>
                    </view>
                    <uni-icons type="arrowright" color="#666"></uni-icons>
                </view>
            </view>
            <view class="ni">
                <view class="ni_cell" @tap="check_upload">
                    <view style="display: flex; align-items: center;">
                        <image style="margin-right: 25rpx; width: 40rpx;height: 40rpx;" src="../../static/aa/xia.png"></image>
                        <label>更新版本</label>
                    </view>
                    <uni-icons type="arrowright" color="#666"></uni-icons>
                </view>
            </view>
        </view>

        <div style="width: 90%;margin: 20px auto;">
            <div class="button1" style="text-align: center" @tap="logout()">
                退出登录
            </div>

        </div>
        <div style="height: 50px;width: 100%"></div>

    </view>
</template>

<script>
    import cache from "../../library/cache.js"
    import http from "../../library/http.js"
    import api from "../../library/index.js"
    import helper from "../../library/helper.js"
    import config from "../../config.js"
    import uniIcons from '../../components/uni-icons/uni-icons.vue'
    import headerline from '../../components/header.vue'
    import silenceUpdate from '@/uni_modules/rt-uni-update/js_sdk/silence-update.js'

    var statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
    var rewardtop = statusBarHeight + 34;
    export default {
        components: {
            uniIcons,
            headerline

        },
        data() {
            return {
                statusBarHeight: statusBarHeight + 'px',
                rewardtop: rewardtop + 'px',
                user: uni.getStorageSync('userInfo'),
                system: uni.getStorageSync('system'),
                msgnum: 0,
                avatar: '',
                getmoeny: false,
                banklen: 0,
                showlayer: false,
                navtitle: '我的'
            }
        },
        
        methods: {

            downapp() {

                window.open(this.system.downurl)

            },
            uploadImage() {

                uni.chooseImage({
                    success: (chooseImageRes) => {
                        const tempFilePaths = chooseImageRes.tempFilePaths;
                        helper.uploadFiles(tempFilePaths, 'image', {
                            type: 'avatar'
                        }).then(res => {

                            this.user.avatar = res;
                            this.avatar = res.replace(config.imgUri, '');
                            var postdata = {
                                id: this.user.id,
                                avatar: this.avatar,
                            };
                            http.setWait(false).post('user.php?act=profile', postdata).then(res => {
                                this.user = res.data;

                                uni.setStorageSync('userInfo', this.user)



                            })
                        })
                    }
                });
            },
            previewAvatar() {
                uni.previewImage({
                    urls: [this.image_cache(this.user.avatar)],

                })
            },
            href(path, opts) {

                if (!opts || opts == undefined || opts == null) opts = {};
                this.$jump(path, opts);

            },
            joinvip() {
                if (this.user.vip == 2) return false;
                this.href('mine.joinvip', {});
            },

            fresh_money() {
                this.getmoeny = true;
                var that = this;

                setTimeout(function() {
                    that.getmoeny = false;
                }, 800)
                this.getuserinfo();
            },
            click_sign() {
                var status = this.$action.check_userlock();
                if (status == true) {
                    var postdata = {
                        userid: uni.getStorageSync('access_token')
                    };
                    http.setWait(false).post('user.php?act=sign', postdata).then(res => {
                        this.getuserinfo();
                        uni.showToast({
                            title: res.data,
                            icon: 'none'
                        })
                    })

                }
            },
            getuserinfo() {
                var postdata = {
                    id: uni.getStorageSync('access_token')
                };
                http.setWait(false).post('user.php?act=userinfo', postdata).then(res => {
                    this.user = res.data;
                    uni.setStorageSync('userInfo', this.user)
                })

            },



            check_upload() {

                let _this = this;

                plus.runtime.getProperty(plus.runtime.appid, function(info) {

                    api.update({
                        version: info.version,
                        osname: plus.os.name
                    }).then(res => {
                          console.log(res,'更新提示');
                        if (res.data.status == 1) {
                            let data  = {
                                describe:'',
                                edition_url:res.data.downurl,
                                edition_force:1, //强制更新
                                package_type:1,//是否整包更新
                                edition_number:'1.1.1',
                                edition_name:'1.1.2',
                                edit_silence:0 
                            }
                            // silenceUpdate(data)
                            uni.navigateTo({
                                url: '/uni_modules/rt-uni-update/components/rt-uni-update/rt-uni-update?obj='+JSON.stringify(data)
                            }); 
                           
                        } else {
                            uni.showToast({
                                icon: 'none',
                                title: '当前已是最新版本',
                                duration: 2000
                            })
                        }
                    })

                });
            },
            logout() {
                uni.showModal({
                    title: '提示',
                    content: '确定要退出吗？',
                    showCancel: true,
                    cancelText: '取消',
                    confirmText: '确定',
                    success: res => {
                        if (res.confirm) {
                            this.$socket.send({
                                type: 'logout',
                                token: uni.getStorageSync('access_token'),

                            });
                            uni.removeStorageSync('access_token');
                            uni.removeStorageSync('userInfo');
                            this.$action.quitcid();
                            //this.$store.commit('chat/clear')
                            //	this.$jump('game.index')
                            uni.reLaunch({
                                url: '/pages/login/index'
                            })
                        }
                    }
                });
            },
        },
        onShow() {
            if (uni.getStorageSync('access_token') > 0) {
                this.getuserinfo();

            } else {
                this.$jump('login.index');
            }

            this.$action.setStatusTips();

        }
    }
</script>

<style lang="scss" scoped>
    .page {
        // background-color: #f8f8f8;
        // min-height: 100vh;
    }
	.flex {
		display: flex;
		align-content: center;
	}
	.margin-tb{
		margin-top: 15upx;
		margin-bottom: 15upx;
	}
    .usercenter {

        display: inline-block;
        width: 100%;


        padding-bottom: 10px;
        position: relative;
        // background: -webkit-linear-gradient(left top, #01d9ff, #01a9fe);
        // background: -o-linear-gradient(bottom right, #01d9ff, #01a9fe);
        // background: -moz-linear-gradient(bottom right, #01d9ff, #01a9fe);
        // background: linear-gradient(to right, #01d9ff, #01a9fe);
        background: #fff;
        height: 125px;
        // color: #fff;
        padding-left: 0px;

    }
    .box-contaniner {
		padding: 20upx;
	}
	.box-shadow{
		padding: 10upx 0;
		background-color: #fff;
		box-shadow: 6upx 4upx 4upx #eee;
		border-radius: 15upx;
	}
	.box-shadow > .showlines:nth-child(1) {
		// padding: 0;
		padding-bottom: 10px;
		border-bottom: 1px solid #eee;
	}
    .usercenter>ul {
		list-style-type: none;
        display: flex;
        flex-direction: row;
        width: calc(100% - 20px);
        padding: 10px 10px;
        margin-top: 30px;
    }

    .usercenter .setting {

        position: absolute;
        right: 20px;
        top: 13px;

        display: inline-block;
        border-radius: 50%;
        color: #fff;
        font-size: 22px;

    }

    .usercenter li {

        vertical-align: middle;
        line-height: 28px;
    }

    .usercenter li:first-child {
        width: 70px;
        text-align: left;
        padding-left: 15px;
        line-height: 30px;
        padding-top: 5px;
    }

    .usercenter li:last-child {
        padding-top: 5px;
        width: calc(100% - 90px);
    }

    .usercenter .avatar {
        height: 60px;
        width: 60px;
        border-radius: 5px;
        vertical-align: top;

    }

    .usercenter .other {
        color: #fff;
        position: absolute;
        right: 15px;
        bottom: 50%;
        line-height: 25px;
        text-align: right;
        display: inline-block;
        width: 60px;
		transform: translate(10px, 50%);
    }

    .usercenter .menu {
        position: absolute;
        left: 0px;
        width: 100%;
        bottom: 0px;
        line-height: 40px;
        height: 40px;
        text-align: center;
        display: table;
        background-color: rgba(0, 0, 0, 0.3);
    }

    .usercenter .menu .row {
        display: table-cell;
        color: #fff;
    }
    .text-gray {
        color: gray;
    }
    .sexbtn {
        height: 16px;
        width: 16px;

        vertical-align: middle;
        border-radius: 5px;
        margin-left: 5px;
        margin-bottom: 5px
    }

    .vipbtn {
        height: 22px;
        width: 22px;

        vertical-align: middle;
        margin-left: 5px;
        margin-bottom: 5px;
    }

    .button1 {
        height: 40px;
        line-height: 40px;
        border: 0px;
        border-radius: 20px;
        color: #fff;
        background: -webkit-linear-gradient(left top, #3388ff, #4399fe);
        background: -o-linear-gradient(bottom right, #3388ff, #4399fe);
        background: -moz-linear-gradient(bottom right, #3388ff, #4399fe);
        background: linear-gradient(to bottom right, #3388ff, #4399fe);
        width: 100%;
        font-size: 16px;
        font-weight: 600;
        text-align: center;
    }

    .icon1 {
        font-size: 16px !important;
        color: #fff !important;
        margin-right: 3px;
    }

    .icon2 {
        font-size: 28px !important;

    }

    .icon3 {
        font-size: 16px !important;
        color: #333 !important;
        margin-right: 1px;
    }

    .fresh {
        transform: rotate(0deg);
        -webkit-transform: rotate(0deg);
        -moz-transform: rotate(0deg);
        -o-transform: rotate(0deg);
        -ms-transform: rotate(0deg);
    }

    .fresh.active {
        transform: rotate(360deg);
        -webkit-transform: rotate(360deg);
        -moz-transform: rotate(360deg);
        -o-transform: rotate(360deg);
        -ms-transform: rotate(360deg);
        transition: all 0.5s ease-in-out;
        -webkit-transition: all 0.5s ease-in-out;
        -moz-transition: all 0.5s ease-in-out;
        -o-transition: all 0.5s ease-in-out;
    }

    .showlines {
        display: flex;
        height: 40px;
        line-height: 40px;
        padding: 5px 0;
        flex-direction: row;
        background-color: #fff;

    }

    .showlines>view {

        flex-direction: row;
        height: 50px;
        line-height: 50px;

    }

    .showlines>view:nth-child(1) {
        width: 60px;
        text-align: center;
        align-items: center;
        justify-content: center;
    }

    .showlines>view:nth-child(2) {
        width: calc(100% - 100px);
        text-align: left;
        font-size: 16px;
        color: #000;
    }

    .showlines>view:nth-child(3) {
        width: 40px;
        text-align: center;
    }

    .showlines image {
        width: 25px;
        height: 25px;
        vertical-align: middle;

    }

    .sign_btn {

        height: 25px;
        line-height: 25px;
        border: 0px;
        border-radius: 5px;

        cursor: pointer;
        padding: 0px 8px;
        text-align: center;
        font-size: 14px;
        font-weight: 600;
        display: inline-block;

        float: right;
    }

    .sign_btn.click {
        color: #fff;
        background: -webkit-linear-gradient(left top, #f05c36, #ff7e00);
        background: -o-linear-gradient(bottom right, #f05c36, #ff7e00);
        background: -moz-linear-gradient(bottom right, #f05c36, #ff7e00);
        background: linear-gradient(to bottom right, #f05c36, #ff7e00);
    }

    .sign_btn i:before {
        margin-left: 0px;
    }

    .sign_btn.ok {
        color: #2319dc;
        background-color: #ccc;
        border: 1px solid #ddd;
        height: 23px;
        line-height: 23px;
    }
</style>